<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *留言记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	$year=date('Y');
	$year=intval($year);
	$id=intval($_RQ['id']);
	if(!$id){
		$mid=intval($_RQ['mid'])?:$_SESSION['uid'];
		$item=pdo_get('jy_51job_merch',array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=pdo_get('jy_51job_merch',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$item['gonginfo']=$item['gonginfo']?json_decode($item['gonginfo'],true):array();
	$item['xueinfo']=$item['xueinfo']?json_decode($item['xueinfo'],true):array();
	$item['xianginfo']=$item['xianginfo']?json_decode($item['xianginfo'],true):array();
	$item['peiinfo']=$item['peiinfo']?json_decode($item['peiinfo'],true):array();
	$item['pcd']=json_decode($item['pcd'],true);
	$item['logo']=tomedia($item['logo']);
	if($item['createtime']>$daytime-2*24*3600){
				$item['isnew']=1;
	}
	if(!$item['isnew'] && $item['uptime']>$daytime){
				$item['isday']=1;
	}
	$item['age']=$item['member']['birth']>0?$year-intval($item['member']['birth']):'';
	$item['typetitle']=$this->job_type[$item['type']];
	$item['teamtypetitle']=$this->teamtype[$item['teamtype']];
	$item['createtime']=date('Y-m-d H:m:s',$item['createtime']);
	$item['jobnum']=pdo_count('jy_51job_job',array('merchid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
	$item['jobtitle']=pdo_getcolumn('jy_51job_job',array('merchid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'title');
	$item['cids']=str_array($item['cids']);
	$item['cidstitle']=array();
	foreach($item['cids'] as $cid){
		$item['cidstitle'][]=pdo_getcolumn('jy_51job_merch_group',array('id'=>$cid,'uniacid'=>$_SESSION['uniacid']),'title');
	}
	$item['mobile2']=$item['member']['mobile'];
	$item['mobile2']=substr($item['mobile2'],0,3).'****'.substr($item['mobile2'],0,4);
	$return['item']=$item;
	$return['params']=array('merchid'=>$item['id']);
	set_html('title','企业详情');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$post=get_postdata();
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
	);
	if(trim($_RQ['keyword'])){
		$return['params']['keyword']=trim($_RQ['keyword']);
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
	if($_RQ['merchid']){
		$params['merchid']=intval($_RQ['merchid']);
		$return['params']['merchid']=intval($_RQ['merchid']);
	}
	if($_RQ['cid']){
		$params['cid']=intval($_RQ['cid']);
		$return['params']['cid']=intval($_RQ['cid']);
	}
	if($_RQ['sid']){
		$params['sid']=intval($_RQ['sid']);
		$return['params']['sid']=intval($_RQ['sid']);
	}
	if($_RQ['ishot']){
		$params['ishot']=intval($_RQ['ishot']);
	}
	if($_RQ['isbao']>0){
		$params['baotype']=intval($_RQ['isbao']);
	}
	if($_RQ['paytype']>0){
		$params['paytype']=intval($_RQ['paytype']);
	}
	if($_RQ['xueli']>0){
		$params['xueli <=']=intval($_RQ['xueli']);
	}
	if($_RQ['cids']){
		$cids=str_array($_RQ['cids']);
		$params['cid']=$cids;
	}
	$return['params']['jsjuli']=intval($_RQ['jsjuli']);
	$return['params']['ishot']=intval($_RQ['ishot']);
	if($_RQ['priceMin']){
		$params['price >=']=$_RQ['priceMin'];
		$return['params']['priceMin']=intval($_RQ['priceMin']);
	}
	if($_RQ['priceMax']){
		$params['price <=']=$_RQ['priceMax'];
		$return['params']['priceMax']=intval($_RQ['priceMax']);
	}
	if($_RQ['city']){
		$params['city']=$_RQ['city'];
		$return['params']['city']=$_RQ['city'];
	}	
	//进一步整理筛选条件，商品属性字段是否需 要调整，商品分类如何筛选，orderby如何整理
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	if(intval($_RQ['num'])){
		$psize=$_RQ['num'];
	}
	$total='';
	$fields=array('id','ishot','title','remark','onlinetime','paytype','baotype','mid','type','price','looks','lat_lng','pay','createtime','province','city','district','merchid');
	$orderby='paixu desc,ishot desc,id desc ';
	if($_RQ['order']){
		if($_RQ['order']=='sales'){
			$orderby='looks desc';
		}
		if($_RQ['order']=='price'){
			if($_RQ['order_type']==2){
				$orderby='price desc';
			}else{
				$orderby='price asc';
			}
		}
	}
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	$list=pdo_getslice('jy_51job_job',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y-m-d H:m:s',$item['createtime']);
			$item['lat_lng']=json_decode($item['lat_lng'],true);
			$item['onlinetime']=json_decode($item['onlinetime'],true);
			if($lat_lng && $item['lat_lng']['lng'] && $item['lat_lng']['lat']){
				$item['juli']=cfc('tools')->getdistance($lat_lng['lng'],$lat_lng['lat'],$item['lat_lng']['lng'],$item['lat_lng']['lat']);
				$item['juli']=price($item['juli']/1000,'ini');
			}
			$item['member']=pdo_get('core_members',array('id'=>$item['mid']));
			$item['images']=json_decode($item['images'],true);
			$item['isme']=$item['mid']==$_SESSION['uid'] ? 1 :0;
			$item['merchname']=pdo_getcolumn('jy_51job_merch',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['merchid']),'title')?:'';
			$item['baotypetitle']=$this->job_paytype2[$item['paytype']].'结('.$this->job_baotype[$item['baotype']].'版)';
		}
	}
	if($_RQ['isjuli']){
		paixu($list,'juli','asc');
	}
	$return['list']=$list;
	exi($return);
}
